//app.js

App({
  onLaunch: function () {
    var that = this

    wx.login({
      success: function (res) {
        that.globalData.loginCode = res.code
      }
    });

    //  获取商城名称
    wx.request({
      url: that.globalData.url + '/config/get-value',
      data: {
        key: 'mallName'
      },
      success: function (res) {
       
        if (res.statusCode == 200){
          wx.setStorageSync('mallName', res.data.value);
        }else{
          wx.showModal({
            title: '错误提示',
            content: res.data.msg,
            showCancel :　false
          })
        }
        
      }
    })
  },
  getUserInfo: function (cb) {
    this.globalData.userInfo = cb.userInfo
    this.globalData.iv = cb.iv
    this.globalData.encryptedData = cb.encryptedData
    let user = cb.userInfo;
    this.globalData.nickname = user.nickName;
  },

  saveOpenId:function(data){

    var that = this;
    wx.request({
      url: that.globalData.COMMON_URL + '/wx-manage/saveUser',
      data : {
        openId: data.openId,
        unionId: data.unionId,
        nickname: data.nickName
      }
    });
    this.globalData.openId = data.openId;
    this.globalData.nickname = data.nickName;
  },

  globalData:{
    userInfo:null,
    appid: 'wx3952810f7390a618',
    appsecret: '0437ed6963c5cd5c88a9c70a244ac036',
    url: 'https://api.it120.cc/jkum',
    COMMON_URL: 'https://api.it120.cc/jkum',
    loginCode: null, 
    encryptedData: null,
    iv: null,
    openId: null,
    nickname:null
  }
})